define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'vppz/medical_staff/index' + location.search+'&ids='+Config.hospital_id,
                    add_url: 'vppz/medical_staff/add?ids='+Config.hospital_id,
                    edit_url: 'vppz/medical_staff/edit',
                    editpassword_url: 'vppz/medical_staff/editpassword',
                    del_url: 'vppz/medical_staff/del',
                    table: 'vppz_medical_staff',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),searchable:false},
                        {field: 'name', title: '名称', operate: 'LIKE'},
						{field: 'community.name', title:'所属社区', operate: 'LIKE',searchable:false},
                        {field: 'avatar', title: '头像', operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image,searchable:false},
                        {field: 'mobile', title: '联系方式', operate: 'LIKE'},
                        {field: 'title', title: '职称', operate: 'LIKE'},
                        {field: 'price', title: '价格', operate: 'LIKE'},
                        {field: 'staff_type', title: __('Staff_type'), searchList: {"doctor":__('Staff_type doctor'),"nurse":__('Staff_type nurse'),"therapist":__('Staff_type therapist')}, formatter: Table.api.formatter.normal},
                        {field: 'on_duty', title: __('on_duty'), searchList: {"0":__('on_duty 0'),"1":__('on_duty 1')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'admin_id', title: __('Admin_id')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [{
                                    name: 'staff',
                                    title: '医师密码',
									text: '医师密码',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'vppz/medical_staff/editpassword'
                                }]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        editpassword: function () {
            Controller.api.bindevent();
        },
		services: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
